package com.zztl.infiniteBand.presenter

import android.content.Context

import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.NoDataResponseBean
import com.zztl.infiniteBand.model.TargetStepBean
import com.zztl.infiniteBand.net.FilterSubscriber2
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.SyncStepRequest
import com.zztl.infiniteBand.ui.view.mvpview.TargetStepView

/**
 * @desc
 * @auth ${user}
 * @time 2018/9/26  15:33
 */
class SportPresenter : BasePresenter<TargetStepView>() {

    fun getTargetStep(context: Context) {

        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                .getTargetStep(""))
                .subscribe(object : FilterSubscriber2<TargetStepBean>(context) {
                    override fun success(bean: TargetStepBean) {
                        view!!.getTargetStep(bean)
                    }

                    override fun fail(msg: String?) {
                        view!!.getTargetStepFail()
                    }


                }))
    }

    fun syncStep(request: SyncStepRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.syncStep(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<NoDataResponseBean>(context) {
                    override fun success(bean: NoDataResponseBean) {
                        view!!.syncStepSuccess(true,request.mileageSum)
                    }

                    override fun fail(msg: String?) {
                        view!!.syncStepSuccess(false, request.mileageSum)
                    }


                }))
    }
}
